#include "painThread.h"
#include <time.h>
#include <QEventLoop>
painThread::painThread()
{	
}

painThread::painThread(Automat *test)
{	
	
	this->test = test;
	int t = test->loadData("sample_map.xml");
	test->init("Nagel");	
}


painThread::~painThread(void)
{
}

void painThread::run()
{
	int i;
	int CarCount;
	int CarId;
	QPoint nowa_pozycja;		
	while(1)
		{
			CarId=0;
			QHash<QPoint,Car> samochody = test->nextMove();
			QHashIterator<QPoint,Car> iterator (samochody);
			
			while(iterator.hasNext())
			{
			iterator.next();
            Car car1 = iterator.value();
            nowa_pozycja = iterator.key();
            CarId = car1.getId();
			emit nextMoveReady(nowa_pozycja, CarId);
			}
			
			QEventLoop loop; 
			connect(this, SIGNAL(doNextMove()), &loop, SLOT(quit())); 
			loop.exec(); 		
		}
}